#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
图片定制工具启动脚本
"""

import os
import sys
from pathlib import Path

# 添加项目根目录到Python路径
project_root = Path(__file__).parent
sys.path.insert(0, str(project_root))

if __name__ == '__main__':
    try:
        # 导入应用
        from app import app
        from config import Config
        
        # 初始化配置
        Config.init_app()
        
        print("=" * 50)
        print("🎨 图片定制工具")
        print("=" * 50)
        print(f"📁 项目目录: {project_root}")
        print(f"🗄️  数据库路径: {Config.DATABASE_PATH}")
        print(f"📤 上传目录: {Config.UPLOAD_FOLDER}")
        print(f"📥 导出目录: {Config.EXPORT_FOLDER}")
        print("=" * 50)
        print("🚀 启动服务器...")
        print("🌐 访问地址: http://localhost:5000")
        print("⏹️  停止服务: Ctrl+C")
        print("=" * 50)
        
        # 启动应用
        app.run(
            debug=True,
            host='0.0.0.0',
            port=5000,
            threaded=True
        )
        
    except ImportError as e:
        print(f"❌ 导入错误: {e}")
        print("💡 请确保已安装所有依赖: pip install -r requirements.txt")
        sys.exit(1)
    except Exception as e:
        print(f"❌ 启动失败: {e}")
        sys.exit(1)
